package com.five.controller.backstage;

import com.alibaba.fastjson.JSON;
import com.five.dao.backstage.RuKuDao;
import com.five.dao.impl.backstage.RuKuDaoImpl;
import com.five.entity.backstage.TRukudetai;
import com.five.entity.backstage.TStaffPwd;
import com.five.util.LayTable;
import com.five.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: jianglin
 * Date: 2020/11/27  17:24
 */
@RestController
@RequestMapping("/ruku")
public class RukuController {
    @Autowired
     private RuKuDao getAllRuKu=  new RuKuDaoImpl();

    @RequestMapping("/addRuku")
    public int ruKuAll(HttpServletRequest req) {
        //接受form表单数据转化为map形式添加入库
        Map map =(Map) JSON.parse(req.getParameter("data"));
        List<Map> table =(List<Map>) JSON.parse(req.getParameter("tableData"));
        int i = getAllRuKu.addRuKu(map);
        int a=0;
        int b=0;
        for (Map map1 : table) {
            a=getAllRuKu.addRuK(map1,i);
            b=getAllRuKu.addRuKus(map1);
        }if (b>0){
            return a;
        }
        return 0;
    }
    //查询入库表所有数据 ，并显示表格中
    @RequestMapping("/queryRuKu")
    public LayTable query(Integer page, Integer limit, TRukudetai tRukudetai){
        int count = getAllRuKu.count(tRukudetai);
        List<Map> map= getAllRuKu.query(page,limit,tRukudetai);
        return new LayTable(count,map);
    }

    @RequestMapping("/queryId")
    public LayTable queryId(Integer ruid){

    List<Map> map =   getAllRuKu.queryRuId(ruid);

        LayTable table = new LayTable(map.size(), map);
        return table;
    }
    //通过设施类型id查询设施
    @RequestMapping("/querySs")
    public  List<Map> querySs(Integer id){
        //System.out.println(id);
        List<Map> map= getAllRuKu.querySs(id);

       return map;
    }
        //查询所有的设施类型
    @RequestMapping("/querySsType")
    public  List<Map> querySsType(){
        List<Map> map= getAllRuKu.querySsType();
        return map;}

        // 通过设施id查询设施
    @RequestMapping("/querySsid")
    public  Map querySsTypeid(Integer id){
        List<Map> map= getAllRuKu.querySsTypeid(id);
        return map.get(0);}

}
